package com.example.newstest.news.fragment;


import android.databinding.Bindable;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.Toolbar;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.newstest.R;
import com.example.newstest.databinding.FragmentNewsBinding;
import com.example.newstest.until.PagerFragmentAdapter;


/**
 * A simple {@link Fragment} subclass.
 */
public class NewsFragment extends Fragment {
    private FragmentNewsBinding binding;
    public NewsFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return DataBindingUtil.inflate(inflater, R.layout.fragment_news,container,false).getRoot();
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        binding = DataBindingUtil.findBinding(view);
        aboutToobar();
        aboutTabLayout();

    }

    private void aboutTabLayout() {
        String[] titles= new String[]{"最新","硬件","软件","手机","科技"};
        PagerFragmentAdapter adapter = new PagerFragmentAdapter(getChildFragmentManager(),titles);
        binding.pager.setAdapter(adapter);
        binding.tablayout.setupWithViewPager(binding.pager);
        binding.pager.setOffscreenPageLimit(5);
    }

    private void aboutToobar() {
        binding.personIcon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(binding.drawerlayout.isDrawerOpen(Gravity.RIGHT)){
                    binding.drawerlayout.closeDrawers();
                }else{
                    binding.drawerlayout.openDrawer(Gravity.RIGHT);
                }
            }
        });
    }
}
